package test.marui.com.mytest.utils;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.support.annotation.Nullable;

/**
 * Created by MR on 2019/1/21.
 */
public class CommonUtil {

    public static Activity getActivity(Context context){

        if (context == null)
            return null;


        if (context instanceof Activity)
            return (Activity)context;

        if (context instanceof ContextWrapper){
            Context context1 = ((ContextWrapper) context).getBaseContext();
            if (context1 instanceof Activity){
                return (Activity)context1;
            }
        }

        return null;
    }

}
